﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Ord4a01DAL : Ord4a01Base
    {
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public SqlApp Modify(Model.Ord4a01 ord4a01)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Ord4a01 set ");
            strSql.Append("pdlistid=@pdlistid ,price=@price ,bqty=@bqty ,ordamt=@ordamt ");
            strSql.Append("where listid=@listid ");
            SqlParameter[] parameters = {
				new SqlParameter("@pdlistid", SqlDbType.NVarChar),
				new SqlParameter("@bqty", SqlDbType.Decimal),
				new SqlParameter("@price", SqlDbType.Decimal),
				new SqlParameter("@ordamt", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.Int)
				};
            parameters[0].Value = ord4a01.Pdlistid;
            parameters[1].Value = ord4a01.Bqty;
            parameters[2].Value = ord4a01.Price;
            parameters[3].Value = ord4a01.Ordamt;
            parameters[4].Value = ord4a01.Listid;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "数据保存失败！");
        }

        public SqlApp DoAdjust(string rowId, double adjQty, double adjAmt)
        {
            var sql = "update ord4a01 set adjqty = isnull(adjqty,0) + @adjqty, adjamt=isnull(adjamt, 0) + @adjamt where listid =@listid";

            SqlParameter[] parameters = {
				new SqlParameter("@adjqty", SqlDbType.Decimal),
				new SqlParameter("@adjamt", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = adjQty;
            parameters[1].Value = adjAmt;
            parameters[2].Value = rowId;

            return new SqlApp(sql, new ArrayList(parameters), false, "数据保存失败！");
        }
    }
}
